From: Jan Beulich Date: Wed, 22 Sep 2021 14:15:29 +0000 (+0200) Subject: AMD/IOMMU: also insert IVMD ranges into Dom0's page tables X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~166 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=a0fe9a1e8c1f28ac528625bd3be99e14a74253ee;p=xen.git AMD/IOMMU: also insert IVMD ranges into Dom0's page tables So far only one region would be taken care of, if it can be placed in the exclusion range registers of the IOMMU. Take care of further ranges as well. Seeing that we've been doing fine without this, make both insertion and removal best effort only. Signed-off-by: Jan Beulich Reviewed-by: Paul Durrant --- diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index 819b5a6cc3..d2678b365a 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -513,6 +513,14 @@ static int amd_iommu_add_device(u8 devfn, struct pci_dev *pdev) amd_iommu_flush_device(iommu, bdf); } + if ( amd_iommu_reserve_domain_unity_map( + pdev->domain, + ivrs_mappings[ivrs_mappings[bdf].dte_requestor_id].unity_map, + 0) ) + AMD_IOMMU_DEBUG("%pd: unity mapping failed for %04x:%02x:%02x.%u\n", + pdev->domain, pdev->seg, pdev->bus, PCI_SLOT(devfn), + PCI_FUNC(devfn)); + return amd_iommu_setup_domain_device(pdev->domain, iommu, devfn, pdev); } @@ -538,6 +546,14 @@ static int amd_iommu_remove_device(u8 devfn, struct pci_dev *pdev) ivrs_mappings = get_ivrs_mappings(pdev->seg); bdf = PCI_BDF2(pdev->bus, devfn); + + if ( amd_iommu_reserve_domain_unity_unmap( + pdev->domain, + ivrs_mappings[ivrs_mappings[bdf].dte_requestor_id].unity_map) ) + AMD_IOMMU_DEBUG("%pd: unity unmapping failed for %04x:%02x:%02x.%u\n", + pdev->domain, pdev->seg, pdev->bus, PCI_SLOT(devfn), + PCI_FUNC(devfn)); + if ( amd_iommu_perdev_intremap && ivrs_mappings[bdf].dte_requestor_id == bdf && ivrs_mappings[bdf].intremap_table )